import {
    showToast,
    showLoadingToast,
    showSuccessToast,
    showFailToast,
    closeToast,
    showDialog,
    showConfirmDialog,
    showNotify
} from "@/components/vant";
import type { ToastOptions, DialogOptions, NotifyOptions } from "vant";

/**
 * Toast 提示工具类
 */
export class ToastUtil {
    /**
     * 普通提示
     */
    static show(message: string, options?: Partial<ToastOptions>) {
        return showToast({
            message,
            duration: 2000,
            ...options
        });
    }

    /**
     * 加载提示
     */
    static loading(message: string = "加载中...", options?: Partial<ToastOptions>) {
        return showLoadingToast({
            message,
            forbidClick: true,
            duration: 0,
            ...options
        });
    }

    /**
     * 成功提示
     */
    static success(message: string, options?: Partial<ToastOptions>) {
        return showSuccessToast({
            message,
            duration: 2000,
            ...options
        });
    }

    /**
     * 失败提示
     */
    static fail(message: string, options?: Partial<ToastOptions>) {
        return showFailToast({
            message,
            duration: 2000,
            ...options
        });
    }

    /**
     * 关闭提示
     */
    static close(all?: boolean) {
        return closeToast(all);
    }
}

/**
 * Dialog 弹窗工具类
 */
export class DialogUtil {
    /**
     * 提示弹窗
     */
    static alert(message: string, options?: Partial<DialogOptions>) {
        return showDialog({
            message,
            showCancelButton: false,
            ...options
        });
    }

    /**
     * 确认弹窗
     */
    static confirm(message: string, options?: Partial<DialogOptions>) {
        return showConfirmDialog({
            message,
            ...options
        });
    }

    /**
     * 自定义弹窗
     */
    static show(options: DialogOptions) {
        return showDialog(options);
    }
}

/**
 * Notify 通知工具类
 */
export class NotifyUtil {
    /**
     * 普通通知
     */
    static show(message: string, options?: Partial<NotifyOptions>) {
        return showNotify({
            message,
            duration: 3000,
            ...options
        });
    }

    /**
     * 成功通知
     */
    static success(message: string, options?: Partial<NotifyOptions>) {
        return showNotify({
            type: "success",
            message,
            duration: 3000,
            ...options
        });
    }

    /**
     * 警告通知
     */
    static warning(message: string, options?: Partial<NotifyOptions>) {
        return showNotify({
            type: "warning",
            message,
            duration: 3000,
            ...options
        });
    }

    /**
     * 危险通知
     */
    static danger(message: string, options?: Partial<NotifyOptions>) {
        return showNotify({
            type: "danger",
            message,
            duration: 3000,
            ...options
        });
    }
}

// 导出简化的函数
export const toast = ToastUtil;
export const dialog = DialogUtil;
export const notify = NotifyUtil;
